import copy

from django.conf import settings
from django.template import Library

register = Library()


@register.inclusion_tag('tag/nb_menu.html')
def nb_menu(request):
    user_menu_list = copy.deepcopy(settings.NB_MENU[request.nb_user.role])
    for item in user_menu_list:
        for child in item['children']:
            if child['name'] == request.nb_user.menu_name:
                child['class'] = 'active'
    return {'menu_list': user_menu_list}
